﻿using System.Collections.Generic;
using System.Linq;
using HTB.DevFx.Utils;

namespace Maple.Weixin.MP.Entities.Menus
{
    public sealed class Button
    {
        private readonly List<MenuBase> menuList = new List<MenuBase>();

        public void AddMenu(MenuBase menu) {
            menuList.Add(menu);
        }

        public string ToJson() {
            var menus = menuList.Take(3).ToArray();
            var entity = new
                {
                    button = new object[menus.Length]
                };
            for (int i = 0; i < menus.Length; i++) {
                entity.button[i] = menus[i].ToJsonObject();
            }

            return JsonHelper.ToJson(entity, true);
        }
    }
}
